package com.shioirikukuri.controller;

import com.shioirikukuri.dto.CouponDistributionDTO;
import com.shioirikukuri.service.IUserCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/usercoupons")
public class UserCouponController {
	@Autowired
	private IUserCouponService userCouponService;

	/**
	 * 发放优惠券（群发）
	 * @param dto 发放优惠券的请求参数
	 * @return 发放结果
	 */
	@PostMapping("/distribute")
	public ResponseEntity<?> distributeCoupon(@RequestBody CouponDistributionDTO dto) {
		try {
			boolean result = userCouponService.distributeCoupon(dto.getMemberLevelId(), dto.getCouponTypeId());
			return ResponseEntity.ok(result ? "优惠券发放成功" : "优惠券发放失败");
		} catch (Exception e) {
			return ResponseEntity.badRequest().body(e.getMessage());
		}
	}

}
